package org.bulu.project.system.service.impl.per;

import org.bulu.project.system.mapper.FavoriteMapper;
import org.bulu.project.system.model.entity.Favorite;
import org.bulu.project.system.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteServiceImpl implements FavoriteService {

    @Autowired
    private FavoriteMapper favoriteMapper;


    @Override
    public List<Integer> getFavorites(Integer id) {
        return favoriteMapper.getVidList(id);
    }

    @Override
    public Favorite addFavorite(Integer uid, String title, String desc, Integer visible) {
        Favorite favorite = new Favorite();
        favorite.setUid(uid);
        favorite.setType(0);
        favorite.setTitle(title);
        favorite.setDescription(desc);
        favorite.setVisible(visible);
        favorite.setIsDelete(0);
        favoriteMapper.insert(favorite);
        return favorite;
    }

    @Override
    public int updateFavorite(Favorite favorite) {
        return favoriteMapper.update(favorite);
    }

    @Override
    public int delFavorite(Integer fid, Integer uid) {
        return favoriteMapper.deleteById(fid);
    }

    @Override
    public Favorite getFavoriteById(Integer fid) {
        return favoriteMapper.queryById(fid);
    }
}
